library(tidyverse)
library(plotly)
library(factoextra)
pstats <- read.csv("../pokemon.csv")
pstats %>% pivot_longer(.,c(HP,Attack,Defence,Sp_attack,Sp_defence,Speed),names_to = "stat") %>% ggplot(aes(x=stat,y=value, fill=stat)) + geom_boxplot() + labs(title = "Distribution of stats") -> p
ggplotly(p)
pstats %>% pivot_longer(.,c(HP,Attack,Defence,Sp_attack,Sp_defence,Speed),names_to = "stat") %>% ggplot(aes(x=stat,y=reorder(value,value),fill=Total,text=Name)) + geom_bar(stat="identity", position="dodge") + labs(title="Pokes oredered by stat", y="value") -> p
ggplotly(p)
pstats %>% pivot_longer(.,c(HP,Attack,Defence,Sp_attack,Sp_defence,Speed),names_to = "stat") %>% ggplot(aes(color=stat,y=value,x=Total,text=Name)) + geom_point() + labs(title="Plotting stats vs PC") -> p
ggplotly(p)
pstats %>% select(HP,Attack,Defence,Sp_attack,Sp_defence,Speed) %>% prcomp() -> pca_poke
pcpoke <- pca_poke$x
pcpoke <- cbind(as.data.frame(pcpoke),nombre=pstats$Name)
pcpoke %>% ggplot(aes(x=PC1,y=PC2, color=PC3, text=nombre)) + geom_point() + labs(title = "Pokes in the 2 PC") -> p
ggplotly(p)
plot_ly(pcpoke, x= ~PC1, y= ~PC2, z= ~PC3, color = ~PC4, text= ~nombre)
## No trace type specified:
## Based on info supplied, a 'scatter3d' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter3d
## No scatter3d mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
fviz_pca_var(pca_poke, col.var = "contrib", gradient.cols=c("#00AFBB","#E7B800","#FC4E07"), repel=TRUE) -> p
p
